home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The Arsenal Files 8
/
The Arsenal Files Collection #8 (Arsenal Computer) (1996).ISO
/
g_quake
/
decoyz.zip
/
DECOY.QC
< prev
next >
Wrap
Text File
|
1996-09-09
|
15KB
|
497 lines
/*
==============================================================================
DECOY AI
==============================================================================
*/
// Prototypes
void () decoy_attack;
float () DecoyFindTarget;
void () decoy_ai_stand;
void () decoy_pain;
void () decoy_die;
void () DecoySightSound;
void () DecoyFoundTarget;
void () DecoyHuntTarget;
void () decoy_ai_turn;
void () decoy_ai_walk;
void () decoy_ai_run;
void (void () thinkst) DecoyCheckRefire;
void (entity decoy) DecoyDestroy;
void (entity decoy) DecoyDeactivate;
void () decoytouch;
void (entity aunit) DecoyCreate;
entity () SelectSpawnPoint;
void (vector org) spawn_tfog;
// Frame macros
$cd /raid/quake/id1/models/player_4
$origin 0 -6 24
$base base
$skin skin
$frame axrun1 axrun2 axrun3 axrun4 axrun5 axrun6
$frame rockrun1 rockrun2 rockrun3 rockrun4 rockrun5 rockrun6
$frame stand1 stand2 stand3 stand4 stand5
$frame axstnd1 axstnd2 axstnd3 axstnd4 axstnd5 axstnd6
$frame axstnd7 axstnd8 axstnd9 axstnd10 axstnd11 axstnd12
$frame axpain1 axpain2 axpain3 axpain4 axpain5 axpain6
$frame pain1 pain2 pain3 pain4 pain5 pain6
$frame axdeth1 axdeth2 axdeth3 axdeth4 axdeth5 axdeth6
$frame axdeth7 axdeth8 axdeth9
$frame deatha1 deatha2 deatha3 deatha4 deatha5 deatha6 deatha7 deatha8
$frame deatha9 deatha10 deatha11
$frame deathb1 deathb2 deathb3 deathb4 deathb5 deathb6 deathb7 deathb8
$frame deathb9
$frame deathc1 deathc2 deathc3 deathc4 deathc5 deathc6 deathc7 deathc8
$frame deathc9 deathc10 deathc11 deathc12 deathc13 deathc14 deathc15
$frame deathd1 deathd2 deathd3 deathd4 deathd5 deathd6 deathd7
$frame deathd8 deathd9
$frame deathe1 deathe2 deathe3 deathe4 deathe5 deathe6 deathe7
$frame deathe8 deathe9
$frame nailatt1 nailatt2
$frame light1 light2
$frame rockatt1 rockatt2 rockatt3 rockatt4 rockatt5 rockatt6
$frame shotatt1 shotatt2 shotatt3 shotatt4 shotatt5 shotatt6
$frame axatt1 axatt2 axatt3 axatt4 axatt5 axatt6
$frame axattb1 axattb2 axattb3 axattb4 axattb5 axattb6
$frame axattc1 axattc2 axattc3 axattc4 axattc5 axattc6
$frame axattd1 axattd2 axattd3 axattd4 axattd5 axattd6
void() decoy_stand1 =[ $stand1, decoy_stand2 ] {decoy_ai_stand();};
void() decoy_stand2 =[ $stand2, decoy_stand3 ] {decoy_ai_stand();};
void() decoy_stand3 =[ $stand3, decoy_stand4 ] {decoy_ai_stand();};
void() decoy_stand4 =[ $stand4, decoy_stand5 ] {decoy_ai_stand();};
void() decoy_stand5 =[ $stand5, decoy_stand1 ] {decoy_ai_stand();};
void() decoy_walk1 =[ $rockrun1 , decoy_walk2 ]{decoy_ai_walk();};
void() decoy_walk2 =[ $rockrun2 , decoy_walk3 ] {decoy_ai_walk();};
void() decoy_walk3 =[ $rockrun3 , decoy_walk4 ] {decoy_ai_walk();};
void() decoy_walk4 =[ $rockrun4 , decoy_walk5 ] {decoy_ai_walk();};
void() decoy_walk5 =[ $rockrun5 , decoy_walk6 ] {decoy_ai_walk();};
void() decoy_walk6 =[ $rockrun6 , decoy_walk1 ] {decoy_ai_walk();};
void() decoy_run1 =[ $rockrun1 , decoy_run2 ]{decoy_ai_run();};
void() decoy_run2 =[ $rockrun2 , decoy_run3 ] {decoy_ai_run();};
void() decoy_run3 =[ $rockrun3 , decoy_run4 ] {decoy_ai_run();};
void() decoy_run4 =[ $rockrun4 , decoy_run5 ] {decoy_ai_run();};
void() decoy_run5 =[ $rockrun5 , decoy_run6 ] {decoy_ai_run();};
void() decoy_run6 =[ $rockrun6 , decoy_run1 ] {decoy_ai_run();};
void() decoy_atk1 =[ $shotatt1, decoy_atk2 ] {ai_face();};
void() decoy_atk2 =[ $shotatt2, decoy_atk3 ] {decoy_attack();};
void() decoy_atk3 =[ $shotatt3, decoy_atk4 ] {ai_face();};
void() decoy_atk4 =[ $shotatt4, decoy_atk5 ] {decoy_attack();};
void() decoy_atk5 =[ $shotatt5, decoy_atk6 ] {ai_face();};
void() decoy_atk6 =[ $shotatt6, decoy_atk1 ]
{
ai_face();
DecoyCheckRefire (decoy_atk1);
};
void() decoy_paina1 =[ $pain1, decoy_paina2 ] {decoy_pain();};
void() decoy_paina2 =[ $pain2, decoy_paina3 ] {};
void() decoy_paina3 =[ $pain3, decoy_paina4 ] {};
void() decoy_paina4 =[ $pain4, decoy_paina5 ] {};
void() decoy_paina5 =[ $pain5, decoy_paina6 ] {};
void() decoy_paina6 =[ $pain6, decoy_run1 ] {};
void() decoy_die1 =[ $deatha1, decoy_die2 ] {decoy_die();};
void() decoy_die2 =[ $deatha2, decoy_die3 ] {};
void() decoy_die3 =[ $deatha3, decoy_die4 ] {};
void() decoy_die4 =[ $deatha4, decoy_die5 ] {ai_forward(14);};
void() decoy_die5 =[ $deatha5, decoy_die6 ] {ai_forward(2);};
void() decoy_die6 =[ $deatha6, decoy_die7 ] {};
void() decoy_die7 =[ $deatha7, decoy_die8 ] {};
void() decoy_die8 =[ $deatha8, decoy_die9 ] {};
void() decoy_die9 =[ $deatha9, decoy_die10 ] {ai_forward(3);};
void() decoy_die10 =[ $deatha10, decoy_die11 ] {};
void() decoy_die11 =[ $deatha11, decoy_die11 ] {DecoyDestroy(self);};
float() DecoyFindTarget =
{
local entity head, selected;
local float dist;
dist = 1500; // awareness radius of decoy, increasing it slows down game
selected = world;
head = findradius(self.origin, 1500);
while(head)
{
if((!(head.flags & FL_NOTARGET) &&
(!(head.items & IT_INVISIBILITY)))
&&
((head.flags & FL_CLIENT)
|| (head.flags & FL_MONSTER)))
if ((head.health > 1) && (head != self))
if (head != self.maker)
if (visible(head))
if (trace_plane_dist < dist)
if ((head.health > 0) && (head !=self))
{
selected = head;
dist = trace_plane_dist;
}
head = head.chain;
}
self.enemy = selected;
if (self.enemy == world)
return FALSE;
else
{
self.oldenemy=self.enemy;
DecoyFoundTarget();
sprint(self.maker, "Decoy Msg: Enemy sighted.\n");
return TRUE;
}
};
//=============================================================
// decoy_ai_stand - decoy stands in place until target acquired,
// and starts to walk if pausetime has expired
//=============================================================
void() decoy_ai_stand =
{
if (DecoyFindTarget ())
return;
if (time > self.pausetime)
{
self.th_walk ();
return;
}
};
//=============================================================
// decoy_ai_walk - decoy is walking, looking for enemies
//=============================================================
void() decoy_ai_walk =
{
if (DecoyFindTarget ())
return;
};
//=============================================================
// decoy_pain
//=============================================================
void() decoy_pain =
{
local float r;
r = random ();
if (r < 0.2)
sound (self, CHAN_VOICE, "player/pain1.wav", 1, ATTN_NORM);
else if (r < 0.3)
sound (self, CHAN_VOICE, "player/pain2.wav", 1, ATTN_NORM);
else if (r < 0.5)
sound (self, CHAN_VOICE, "player/pain3.wav", 1, ATTN_NORM);
else if (r < 0.7)
sound (self, CHAN_VOICE, "player/pain4.wav", 1, ATTN_NORM);
else if (r < 0.8)
sound (self, CHAN_VOICE, "player/pain5.wav", 1, ATTN_NORM);
else
sound (self, CHAN_VOICE, "player/pain6.wav", 1, ATTN_NORM);
};
//=============================================================
// decoy_die
//=============================================================
void() decoy_die =
{
sound (self, CHAN_VOICE, "player/h2odeath.wav", 1, ATTN_NORM);
};
//=============================================================
// DecoySightSound
//=============================================================
void() DecoySightSound =
{
local float rsnd;
rsnd = rint(random() * 3);
if (rsnd == 1)
sound (self, CHAN_VOICE, "weapons/lock4.wav", 1, ATTN_NORM);
else if (rsnd == 2)
sound (self, CHAN_VOICE, "weapons/pkup.wav", 1, ATTN_NORM);
else if (rsnd == 0)
sound (self, CHAN_VOICE, "weapons/grendade.wav", 1, ATTN_NORM);
else
sound (self, CHAN_VOICE, "weapons/spike2.wav", 1, ATTN_NORM);
};
//=============================================================
// decoyHuntTarget
//=============================================================
void() DecoyHuntTarget =
{
self.goalentity = self.enemy;
self.think = self.th_run;
self.ideal_yaw = vectoyaw(self.enemy.origin - self.origin);
self.nextthink = time + 0.1;
SUB_AttackFinished (0.1); // wait a while before first attack
};
//=============================================================
// DecoyFoundTarget
//=============================================================
void() DecoyFoundTarget =
{
local float f_dist;
local string s_dist;
f_dist = vlen (self.enemy.origin - self.origin);
s_dist = ftos (f_dist);
DecoySightSound ();
DecoyHuntTarget ();
};
//=============================================================
// decoy_ai_turn - turn towards ideal_yaw if no enemy sighted
//=============================================================
void() decoy_ai_turn =
{
if (DecoyFindTarget ())
return;
ChangeYaw ();
};
//=============================================================
// decoy_ai_run - still needs a little work
//=============================================================
void() decoy_ai_run =
{
local vector delta;
local float axis;
local float direct, ang_rint, ang_floor, ang_ceil;
if (self.enemy.health <= 0)
{
self.enemy = world;
if (self.oldenemy.health > 0)
{
self.enemy = self.oldenemy;
DecoyHuntTarget ();
}
else
{
if (DecoyFindTarget())
return;
else
{
self.th_stand ();
return;
}
}
}
enemy_vis = visible(self.enemy);
if (enemy_vis)
self.search_time = time + 5;
enemy_infront = infront(self.enemy);
enemy_range = range(self.enemy);
enemy_yaw = vectoyaw(self.enemy.origin - self.origin);
if (CheckAnyAttack ())
return; // beginning an attack
if (self.attack_state == AS_SLIDING)
{
ai_run_slide ();
return;
}
};
//=============================================================
// DecoyCheckRefire
//=============================================================
void (void () thinkst) DecoyCheckRefire =
{
if (!visible (self.enemy) || (self.enemy.health <= 0))
{
if (self.enemy.health <= 0)
{
if (self.oldenemy.health>0) //if oldenemy still kickin
self.enemy=self.oldenemy; //change to old enemy
HuntTarget(); //Hunt him down
}
return;
}
self.think = thinkst;
};
//=============================================================
// DecoyActivate - Activates the decoy
//=============================================================
void (entity aunit) DecoyCreate =
{
local entity newdecoy;
newdecoy = spawn();
newdecoy.solid = SOLID_SLIDEBOX;
newdecoy.movetype = MOVETYPE_STEP;
newdecoy.angles = self.angles;
newdecoy.classname = "decoy";
newdecoy.maker = self;
newdecoy.skin = self.skin;
newdecoy.health = 100;
newdecoy.max_health = 100;
newdecoy.takedamage = DAMAGE_AIM;
newdecoy.goalentity = self;
newdecoy.movetarget = self;
newdecoy.pausetime = time + 2;
newdecoy.ideal_yaw = newdecoy.angles * '0 1 0';
newdecoy.yaw_speed = 90;
newdecoy.weapon = 2;
newdecoy.ammo_shells = 100;
newdecoy.view_ofs = '0 0 25';
newdecoy.touch = decoytouch;
newdecoy.th_stand = decoy_stand1;
newdecoy.th_walk = decoy_walk1;
newdecoy.th_run = decoy_run1;
newdecoy.th_pain = decoy_paina1;
newdecoy.th_die = decoy_die1;
newdecoy.th_missile = decoy_atk1;
setmodel (newdecoy, "progs/player.mdl");
setsize (newdecoy, '-16 -16 -24', '16 16 40');
setorigin(newdecoy, aunit.origin + '0 0 50');
remove(aunit);
spawn_tfog (newdecoy.origin);
bprint("New Decoy Created \n");
newdecoy.nextthink = time + 0.1;
newdecoy.think = newdecoy.th_stand;
};
//=============================================================
// DecoyDestroy - Decoy destroys itself
//=============================================================
void (entity decoy) DecoyDestroy =
{
decoy.solid = SOLID_NOT;
T_RadiusDamage(decoy, world, 150, world);
WriteByte(MSG_BROADCAST, SVC_TEMPENTITY);
WriteByte(MSG_BROADCAST, TE_EXPLOSION);
WriteCoord(MSG_BROADCAST, decoy.origin_x);
WriteCoord(MSG_BROADCAST, decoy.origin_y);
WriteCoord(MSG_BROADCAST, decoy.origin_z);
setmodel(decoy, "progs/s_explod.spr");
remove(decoy);
sprint(decoy.maker, "Decoy detonated.\n");
};
void (entity decoy) DecoyDeactivate =
{
decoy.maker.currentammo = decoy.maker.ammo_rockets = decoy.maker.ammo_rockets + 1;
decoy.maker.currentammo = decoy.maker.ammo_cells = decoy.maker.ammo_cells + 1;
remove(decoy);
sprint(decoy.maker, "Decoy switched off.\n");
sprint(decoy.maker, "Ammo retrieved.\n");
};
void() decoytouch =
{
if (other == world)
return;
if (self.maker == other)
return;
if (other.classname == "spike")
return;
if (other.classname == "grenade")
return;
if (other.classname == "dactivator")
return;
if (other.movetype == MOVETYPE_FLYMISSILE)
return;
DecoyDestroy(self);
};
void() decoy_FireShotgun =
{
local vector dir;
sound (self, CHAN_VOICE, "weapons/guncock.wav", 1, ATTN_NORM);
self.effects = self.effects | EF_MUZZLEFLASH;
dir = aim (self, 100000);
// FireBullets (6, dir, '0.04 0.04 0');
};
/*
==========================
decoy_attack - fires weapon
==========================
*/
void() decoy_attack =
{
local float r;
if (!visible (self.enemy) || (self.enemy.health <= 0))
return;
makevectors (self.angles);
decoy_FireShotgun ();
};